<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInviteOneOnOneTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::create('invite_one_on_one_students', function (Blueprint $table) {
            $table->timestamp('updated_at')->useCurrent();
            $table->timestamp('created_at');

            $table->integer('student_id')->comment('邀请用户ID');
            $table->integer('has_billing')->default(0)->comment('是否购买');
            $table->integer('has_consumption')->default(0)->comment('是否上课');
            $table->tinyInteger('status')->default(0)->comment('状态[0无特权,1有特权]');

            $table->softDeletes();

            $table->primary("student_id");
        });
        Schema::create('invite_one_on_one_shares', function (Blueprint $table) {
            $table->timestamp('updated_at')->useCurrent();
            $table->timestamp('created_at');

            $table->increments('id');
            $table->integer('student_id')->comment('邀请用户ID');
            $table->string('share_code')->comment('分享code');
            $table->integer('accepted_num')->default(0)->comment('被领取次数');
            $table->tinyInteger('status')->default(0)->comment('状态[0正常,1抢完,2过期]');
            $table->timestamp('expired_at')->comment('过期时间');

            $table->softDeletes();

            $table->index('student_id');
            $table->index('share_code');
        });
        Schema::create('invite_one_on_one_acceptances', function (Blueprint $table) {
            $table->timestamp('updated_at')->useCurrent();
            $table->timestamp('created_at');

            $table->increments('id');
            $table->integer('share_id')->comment('福袋ID');
            $table->integer('student_id')->comment('领取用户ID');

            $table->softDeletes();

            $table->index('student_id', 'type');
            $table->index('share_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::drop('invite_one_on_one_students');
        Schema::drop('invite_one_on_one_shares');
        Schema::drop('invite_one_on_one_acceptances');
    }
}
